package it.av.training.rest.exception;

import org.apache.log4j.Level;

/**
 * General exception. 
 * 
 * @author alessandro vincelli
 * 
 */
public class RestException extends RuntimeException {

    /**
     * default serial version
     */
    private static final long serialVersionUID = 1L;
    private ErrorCode errorCode;

    private String guid;

    /**
     * @param message
     * @param errorCode
     * @param className
     * @param severity
     */
    public RestException(String message, ErrorCode errorCode, String className, Level severity) {
        super(message);
        this.errorCode = errorCode;
        this.guid = GuidSequence.getInstance().nextGuid();
        ExceptionLogger.log(this, className, severity);
    }

    /**
     * @param message
     * @param errorCode
     * @param className
     * @param severity
     * @param cause
     */
    public RestException(String message, ErrorCode errorCode, String className, Level severity, Throwable cause) {
        super(message, cause);
        this.errorCode = errorCode;
        this.guid = GuidSequence.getInstance().nextGuid();

        ExceptionLogger.log(this, className, severity);
    }

    public ErrorCode getErrorCode() {
        return errorCode;
    }

    public String getGuid() {
        return guid;
    }

}
